<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/store/include/init_store.jsp" %>
<%

	if (!isSeller) {
		response.sendRedirect("/");
		return ;
	}

	
	String issue_id	= StringUtil.nvl(request.getParameter("issue_id"));
	String job_type		= "".equals(issue_id) ? "C" : "U";
	
	HashMap infos = new HashMap();
	infos.put("issue_id", issue_id);
	
	PublisherDAO dao = new PublisherDAO();
	HashList info 	= dao.selectCouponInfo(infos);
	HashList list 	= dao.selectCouponNoList(infos);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= HOME_NAME %></title>
	<%@ include file="/home/include/cssnjs.jsp"  %>
	<link rel="stylesheet" type="text/css" href="../../css/smoothness/jquery-ui-1.8.17.custom.css" media="screen" />
	<script type="text/javascript" src="../../js/jquery-ui-1.8.18.custom.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="../../js/jquery.maskedinput-1.3.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="../../js/jquery.ui.datepicker-ko.js" charset="utf-8"></script>
	<script type="text/javascript">
	var oEditors = [];
	$(document).ready(function() {
		$('#store_main li:nth-child(3)').addClass('on');
		$('#start_dt').mask('9999.99.99').datepicker();
		$('#end_dt').mask('9999.99.99').datepicker();
	});

	function fnIssue() {
		if (cfCheckRequired(document.saveForm.book_code, "큐북을 선택하세요")
		&& cfCheckRequired(document.saveForm.issue_count, "발행매수를 선택하세요")) 
		{
			if (confirm("쿠폰을 발행하시겠습니까?")) 
			{
				$('#saveForm').attr('action', './couponSave.do');
				$('#saveForm').submit();
			}
		}
	}
	
	function fnSelectQbook() {
		cfOpen('./selectBook.jsp','selectBook', 600, 400)
	}
	
	function fnSave() {
		if (confirm(MSG_SAVE)) 
		{
			$('#saveForm').attr('action', './couponSave.do');
			$('#saveForm').submit();
		}
	}

	function fnDelete() {
		if (confirm(MSG_DELETE)) 
		{
			$('#job_type').val("D");
			$('#saveForm').attr('action', './couponSave.do');
			$('#saveForm').submit();
		}
	}

	function fnExcel() {
		$('#saveForm').attr('action', './couponNoListExcel.jsp');
		$('#saveForm').submit();
		$('#saveForm').attr('action', './couponDetail.jsp');
	}
	</script>
</head>
<body>
<div id="wrap">
	<%@ include file="/publisher/include/header.jsp"  %>
	<div id="contents">
		<h2>쿠폰관리</h2>

		<form id="saveForm" name="saveForm"  method="post" action="./couponSave.do">
		<input type="hidden" name="job_type" id="job_type" value="<%= job_type %>"/>
		<input type="hidden" name="publisher_id" value="<%= session_user_id %>"/>
		<input type="hidden" name="issue_id" value="<%= issue_id %>"/>
		

		<table cellpadding="0" cellspacing="0" class="table_01 mt15">
		<colgroup>
			<col width="100px"/>
			<col width="360px"/>
			<col width="100px"/>
			<col/>
		</colgroup>
		<tbody>
			<tr>
				<th>큐북*</th>
				<td colspan="3">
			<%	if ("U".equals(job_type)) { %>
					[<%= info.get("book_code", 0) %>] <%= info.get("book_name",0) %>
			<%	} else { %>
					<input type="text" class="text w100" name="book_code" id="book_code" readonly="readonly" value="<%= info.get("book_code", 0) %>"  /> 
					<a href="#nohref" onclick="fnSelectQbook()"><img src="./images/ico_qbook_select.gif"/></a>
					<label id="book_name"/> 
			<%	} %>
				</td>
			</tr>
			<tr>
				<th>발행매수*</th>
				<td>
			<%	if ("U".equals(job_type)) { %>
					<%= info.get("issue_count",0) %> 매
			<%	} else { %>
					<input type="radio" name="issue_count" value="100" > 100 매</input>
					<input type="radio" name="issue_count" value="300" > 300 매</input>
					<input type="radio" name="issue_count" value="500" > 500 매</input>
					<input type="radio" name="issue_count" value="1000" > 1,000 매</input>
			<%	} %>
				</td>
				<th>유효기간</th>
				<td >
					<input type="text" name="end_dt" id="end_dt" class="w100 c" value="<%= info.getDate("end_dt", 0) %>"/>
				</td>
			</tr>
			<tr>
				<th>비고</th>
				<td colspan="3">
					<input type="text" class="text wmax" name="remarks" value="<%= info.get("remarks", 0) %>"  /> 
				</td>
			</tr>
		</tbody>
		</table>
		
		
		<div class="mt10 c">
	<%	if ("U".equals(job_type)) { %>
			<a href="./couponList.jsp"><img src="./images/btn_list.gif"/></a>
			<a href="#nohref" onclick="fnExcel()"><img src="./images/btn_excel.gif"/></a>
			<a href="#nohref" onclick="fnSave()"><img src="./images/btn_save.gif"/></a>
			<a href="#nohref" onclick="fnDelete()"><img src="./images/btn_delete.gif"/></a>
	<%	} else if ("C".equals(job_type)) { %>
			<a href="#nohref" onclick="fnIssue()"><img src="./images/btn_coupon.gif"/></a>
			<a href="./couponList.jsp"><img src="./images/btn_cancel.gif"/></a>
	<%	} %>
		</div>
		
		<table cellpadding="0" cellspacing="0" class="table_01 mt15">
			<colgroup>
				<col width="60px"/>
				<col/>
				<col width="160px"/>
				<col width="160px"/>
			</colgroup>
			<thead>
				<tr>
					<th><p>No</p></th>
					<th><p>쿠폰번호</p></th>
					<th><p>사용일자</p></th>
					<th><p>발행일자</p></th>
				</tr>
			</thead>
			<tbody id="list">
			<%	for (int i = 0; i < list.size(); i++) { %>
				<tr>
					<td class="c"><%= i+1 %></td>
					<td><%= CommonUtil.toCouponNo(list.get("coupon_no",i))%></td>
					<td class="c"><%= list.get("use_date",i) %></td>
					<td class="c"><%= list.get("init_date",i) %></td>
				</tr>
			<%	} %>
			
			</tbody>
		</table>
			
			





		</form>
	

	</div>
		
		<%@ include file="/publisher/include/footer.jsp"  %>	
</div>
</body>
</html>
